package com.itheima.reggie.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.mapper.DishMapper;
import com.itheima.reggie.service.CategoryService;
import com.itheima.reggie.service.DishFlavorService;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements DishService {
    @Autowired
   private DishFlavorService dishFlavorService;


    /**
     * 添加
     * @param dishDto
     */
    @Override
    @Transactional
    public void saveDishFlavor(DishDto dishDto) {
        //保存数据,生成雪花算法id
        this.save(dishDto);
        Long id = dishDto.getId();
//        从flavor里面获取所有数据,对每个口味进行id设置
        dishDto.getFlavors().forEach(s -> s.setDishId(id));
        dishFlavorService.saveBatch(dishDto.getFlavors());
    }

    @Override
    public List<DishDto> getList(Dish dish) {
      List<DishDto>  list=baseMapper.getList(dish);
        return list;
    }


}
